import time
from threading import Thread
from multiprocessing import Process

def count(n):
    for i in range(n):
        print(f"count{i}")
        time.sleep(0.1)

def hello(name):
    for i in range(5):
        print(f"hello,{name}")
        time.sleep(0.1)

#逐个运行
if __name__ == "__main__":
    start_time = time.time()
    count(10)
    hello("lili")
    end_time = time.time()
    print(f"单独运行总耗时{end_time-start_time}s")

#多线程运行
if __name__ == "__main__":
    start_time = time.time()
    c = Thread(target=count(10),)
    h = Thread(target=hello("lili"),)
    c.start()
    h.start()
    end_time = time.time()
    print(f"多线程运行总耗时{end_time-start_time}s")

#多进程运行
if __name__ == "__main__":
    start_time = time.time()
    c = Process(target=count(10),)
    h = Process(target=hello("lili"),)
    c.start()
    h.start()
    end_time = time.time()
    print(f"多进程运行总耗时{end_time-start_time}s")